home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Syn Text Editor 2.1.0.46 / synsetup-2.1.0.46.exe / {app} / scripts / img_src.vbs < prev    next >
Text File  |  2003-08-13  |  2KB  |  90 lines

  1. ' Caption: Insert IMG tag|
  2. ' Hint: Insert an IMG SRC tag|
  3. ' Icon: img_src.ico|
  4. '
  5. '  img src tag.
  6. '
  7. '  The contents of this file are subject to the Mozilla Public License
  8. '  Version 1.1 (the "License"); you may not use this file except in compliance
  9. '  with the License. You may obtain a copy of the License at
  10. '  http://www.mozilla.org/MPL/
  11. '
  12. '  Software distributed under the License is distributed on an "AS IS" basis,
  13. '  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  14. '  the specific language governing rights and limitations under the License.
  15. '
  16. '  The Initial Developer of the Original Code is Magoga Demis.
  17. '  Portions created by Magoga Demis are Copyright (C) 2000-2003 Magoga Demis.
  18. '  All Rights Reserved.
  19. '
  20. ' $Id: img_src.vbs,v 1.2.2.5 2003/08/13 00:38:45 neum Exp $
  21. '
  22.  
  23. option explicit
  24.  
  25. '#include <cmnfunc>
  26.  
  27. on error resume next
  28.  
  29. ' non togliere il parametro dummy
  30. sub Main(FileName)
  31.  
  32.     ' vars
  33.     dim image
  34.     dim pic
  35.     dim file
  36.     dim divX
  37.     dim divY
  38.     dim dlg
  39.     dim pos
  40.     dim l1
  41.     dim l2
  42.     dim docPath
  43.     dim refPic
  44.     
  45.     if Documents.Count = 0 then
  46.       exit sub
  47.     end if
  48.     
  49.     'ref pic to calculate twips
  50.     Set refPic=LoadPicture(AddBackslash(ExtractFilePath(FileName)) & "1000x1000.gif")
  51.     'Assume the reference picture is in the path from the script, not relative to
  52.     'the program, more secure, I think.
  53.  
  54.     'get scale
  55.     divX=refPic.width/1000
  56.     divY=refPic.height/1000
  57.     
  58.     'chose the image to insert
  59.     Set dlg=Create("TOpenDialog", Self)
  60.     dlg.Title="Choose a picture"
  61.     dlg.Filter="Pictures (*.jpg,*.gif)|*.jpg;*.gif|All Files (*.*)|*.*"
  62.     if not dlg.Execute then
  63.         exit sub
  64.     end if
  65.  
  66.     'file name
  67.     file=dlg.FileName
  68.     
  69.     'load pic
  70.     Set pic=LoadPicture(file)
  71.     docPath=ActiveDocument.FilePath & "\"
  72.     
  73.     'index of curr dir
  74.     pos=inStr(file, docPath)
  75.     
  76.     'in a sub dir calculate relative path
  77.     if pos<>0 then
  78.         l1=Len(docPath)
  79.         l2=Len(file)
  80.         file=Right(file, l2-l1)
  81.     end if
  82.     
  83.     'no \ but /
  84.     file=Replace(file, "\", "/")
  85.  
  86.     'write the tag
  87.     ActiveDocument.SelText= "<img src=""" & file & """ border=""0"" width=""" & Round(pic.width/divX, 0) & """ height=""" & Round(pic.height/divY, 0) & """>"
  88.  
  89. end sub
  90.